package ru.osu.acm.testing.listeners;

import ru.osu.acm.testing.beans.DataBean;

import javax.faces.application.NavigationHandler;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
import javax.servlet.http.HttpSession;

/**
 * User: Aleksey
 * Date: 03.03.2009
 * Time: 14:41:18
 */
public class DeadSessionListener implements PhaseListener {
    public void afterPhase(PhaseEvent phaseEvent) {
        /*FacesContext facesCtx = phaseEvent.getFacesContext();
        HttpSession session = (HttpSession) facesCtx.getExternalContext().getSession(false);
        if (session == null) {
            NavigationHandler nh = facesCtx.getApplication().getNavigationHandler();
            nh.handleNavigation(facesCtx, "temp", "/temp.html");
        }*/
        /*FacesContext facesCtx = phaseEvent.getFacesContext();
        HttpSession session = (HttpSession) facesCtx.getExternalContext().getSession(false);
        Boolean loggedIn = session.getAttribute("data") != null && ((DataBean) session.getAttribute("data")).getUser().isLoggedIn();
        if (!facesCtx.getViewRoot().getViewId().contains("register")) {
            if (!facesCtx.getViewRoot().getViewId().contains("login") && !loggedIn) {
                NavigationHandler nh = facesCtx.getApplication().getNavigationHandler();
                nh.handleNavigation(facesCtx, null, "treter");
            }
        }*/
    }

    public void beforePhase(PhaseEvent phaseEvent) {
    }

    public PhaseId getPhaseId() {
        return PhaseId.RESTORE_VIEW;
    }
}